<?php

namespace App\Admin\Extensions\Table;

use App\Admin\Repositories\ShopGood;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class ShopGoodTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $id = $this->id;
        return Grid::make(new ShopGood(), function (Grid $grid) {
            $grid->model()->select(["shop_goods.*"])->with(['shop','goods'])
                ->join("goods","goods.id","=","shop_goods.good_id")
                ->where("goods.cate","=","real")
                ->orderByDesc("id");
            $grid->column('id');
            $grid->column('goods.image','商品图片')->image(null,40,40);
            $grid->column('goods.name','商品名称');
            $grid->column('goods.category.name','商品分类');
            $grid->column('shop.name','店铺名称');
            $grid->column('created_at');
            $grid->quickSearch(['id', 'goods.name','goods.category.name', 'shop.name']);
            $grid->paginate(8);
            $grid->disableActions();
        });
    }
}
